<template>
  <view class="mdlBox">

    <view v-if="type==0">
      <view class="mdlBoxTitle">提币类型：</view>
      <view class="mdlInput" >
        <picker @change="bindPickerChange" :value="index" :range="array">
          <view style="padding-top: 7px;">{{array[index]}}</view>
        </picker>
      </view>
      <view v-if="show">
        <view class="mdlBoxTitle">交易所UID：</view>
        <view class="mdlInput" >
          <input type="text" v-model="uid" placeholder="请输入交易所UID" :style="uid!==''?'border-bottom: 1px solid #FC9F56':''"/>
        </view>

        <view class="mdlBoxTitle">交易所地址：</view>
        <view class="mdlInput">
          <input type="text" v-model="communicateAddress" placeholder="请输入交易所地址" :style="communicateAddress!==''?'border-bottom: 1px solid #FC9F56':''"/>
        </view>

        <view class="mdlBoxTitle">钱包地址：</view>
        <view class="mdlInput">
          <input type="text" v-model="walletAddress" placeholder="请输入钱包地址" :style="walletAddress!==''?'border-bottom: 1px solid #FC9F56':''"/>
        </view>
      </view>

    </view>
    <view v-else>
      <view class="mdlBoxTitle">去中心地址：</view>
      <view class="mdlInput">
        <input type="text" v-model="centerAddress" placeholder="请输入去中心地址" />
      </view>
    </view>


    <view class="confirmBtn" @click="confirmBtn">确认</view>
  </view>
</template>

<script>

import { withdrawalApply , getCenterAddress , saveCenterAddress} from "@/api/product";
export default {
  data() {
    return {
      money:'888.78',
      uid:'',
      array: ['代理质押费解锁','流动提现至交易所'],
      index: 1,
      show: true,
      communicateAddress:'',
      walletAddress:'',
      centerAddress:'',
      type:0,
      transfer_type:2
    };
  },
  onLoad(option){
    this.type = option.type
    if (option.type==1){
      uni.setNavigationBarTitle({
        title:'去中心地址'
      })
      this.$get(`${getCenterAddress}`, {}).then(async r => {
        this.centerAddress = r.data.center_address
      }).catch(err => {
        console.log(err);
      })
    }


  },
  methods:{
    bindPickerChange: function(e) {
      this.index = e.target.value;
      if (this.index == 1){
        this.show = true;
        this.transfer_type = 2;
      }else{
        this.show = false;
        this.transfer_type = 1;
      }
    },
    confirmBtn: function() {

      if (this.type==1){
        this.$post(`${saveCenterAddress}`, { center_address: this.centerAddress }).then(async r => {
          this.$api.msg('修改成功')
          setTimeout(function (){
            uni.navigateBack()
          },2000)
        }).catch(err => {
          console.log(err);
        })
      }else{
        let data = {} ;
        data.transfer_type = this.transfer_type;
        if (this.transfer_type == 1){
          uni.showModal({
            content: '是否自愿放弃当前代理身份？',
            confirmText:'是',
            cancelText:'否',
            success: (confirmRes) => {
              if (confirmRes.confirm) {
                this.$post(`${withdrawalApply}`, data).then(async r => {
                  this.$api.msg('您的申请已提交，请耐心等待')
                  setTimeout(function (){
                    uni.navigateBack()
                  },2000)

                }).catch(err => {

                  console.log(err);
                })
              }
            }
          });
        }else{
          if (this.uid == '' && this.communicateAddress == '' && this.walletAddress == ''){
            this.$api.msg('请填写提币信息');
            return
          }
          data.house_uid = this.uid;
          data.house_address = this.communicateAddress;
          data.house_wallet = this.walletAddress;
          uni.showModal({
            content: '是否提现至交易所？',
            confirmText:'是',
            cancelText:'否',
            success: (confirmRes) => {
              if (confirmRes.confirm) {
                this.$post(`${withdrawalApply}`, data).then(async r => {
                  this.$api.msg('您的申请已提交，请耐心等待')
                  setTimeout(function (){
                    uni.navigateBack()
                  },2000)

                }).catch(err => {

                  console.log(err);
                })
              }
            }
          });
        }



      }

    }
  }
}
</script>

<style lang="less" >

page{
  background: #fff;
}
.mdlBox{
  width: 92%;
  margin: 0 auto;
}
.mdlBoxTitle{
  font-size: 32upx;
  font-family: PingFang SC;
  font-weight: bold;
  color: #343434;
  margin-top: 40upx;
  line-height: 60upx;
}

.mdlMoney{
  color: #F87D29;
  font-size: 40upx;
  font-family: PingFang SC;
  font-weight: bold;
  margin-bottom: 30rpx;
}
.mdlInput{
	input{
		font-size: 28rpx;
		width: 65%;
		line-height: 70upx;
		height: 70upx;
		border-bottom: 1px solid #f4f0f0;
	}
  picker{
		font-size: 28rpx;
		width: 65%;
		line-height: 70upx;
		height: 70upx;
    border-bottom: 1px solid rgb(252, 159, 86);
	}

}

.select{
  font-size: 24upx;
  color: #666666;
}

.confirmBtn{
  height: 88upx;
  font-size: 32upx;
  font-family: PingFang SC;
  font-weight: bold;
  color: #FFFFFF;
  line-height: 88upx;
  background: #FC9F56;
  text-align: center;
  border-radius: 16upx;
  position: fixed;
  bottom: 24upx;
  width: 92%;
}
</style>
